package com.manage.competition.service.impl;

import com.manage.competition.entity.CompetitionInformation;
import com.manage.competition.mapper.CompetitionInformationMapper;
import com.manage.competition.repository.CompetitionInformationRepository;
import com.manage.competition.service.ICompetitionInformationService;
import com.manage.competition.util.CurrentUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Create with IDEA
 *
 * @Author: gitee.com/KamisamaXX
 * @Date: Create in 13:23 2019/3/31
 * @Description:
 */
@Service
public class CompetitionInformationServiceImpl implements ICompetitionInformationService {

    @Autowired
    private CompetitionInformationMapper competitionInformationMapper;

    @Autowired
    private CompetitionInformationRepository competitionInformationRepository;

    @Override
    public int insert(CompetitionInformation competitionInformation) {
        competitionInformation.setCreateUser(CurrentUserUtil.getCurrentUser().getUsername());
        competitionInformation.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return competitionInformationMapper.insert(competitionInformation);
    }

    @Override
    public int update(CompetitionInformation competitionInformation) {
        competitionInformation.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return competitionInformationMapper.updateByPrimaryKeySelective(competitionInformation);
    }

    @Override
    public CompetitionInformation getById(long id) {
        return competitionInformationRepository.findById(id).orElse(null);
    }

    @Override
    public int deleteByPrimaryKey(Long informationId) {
        return competitionInformationMapper.deleteByPrimaryKey(informationId);
    }
}
